package cn.edu.jxau.test;

import java.util.Arrays;
import java.util.Objects;

//-----------------------------
// 解法1:效率太低
//-----------------------------
//public class Main {
//
//	public static void main(String[] args) {
//		probability(3);
//	}
//
//	public static void probability(int n) {
//
//		if (n <= 0) {
//			throw new IllegalArgumentException("参数n必须是正数");
//		}
//		int[] arr = new int[6 * n - n + 1]; // n个骰1子和为arr[i]出现的次数
//		probability(n, n, arr, 0);
//		System.out.println(Arrays.toString(arr));
//		int denominator = (int) Math.pow(6, n);
//		int index = 0;
//		for (int i = n, end = 6 * n; i <= end; i++) {
//			System.out.printf("%d:%d/%d\n", n + arr[index], arr[index], denominator);
//			index++;
//		}
//	}
//
//	public static void probability(int n0, int n, int[] arr, int s) {
//		if (n <= 0) {
//			arr[s - n0]++;
//			return;
//		}
//		for (int i = 1; i <= 6; i++) {
//			probability(n0, n - 1, arr, s + i);
//		}
//	}
//}

//-----------------------------
// 解法2
//-----------------------------
public class Main {

	public static void main(String[] args) {
		probability(3);
	}

	public static void probability(int n) {

		if (n <= 0) {
			throw new IllegalArgumentException("参数n必须是正数");
		}
		int[] arr = new int[6 * n - n + 1]; // n个骰1子和为arr[i]出现的次数
		probability(n, n, arr, 0);
		System.out.println(Arrays.toString(arr));
		int denominator = (int) Math.pow(6, n);
		int index = 0;
		for (int i = n, end = 6 * n; i <= end; i++) {
			System.out.printf("%d:%d/%d\n", n + arr[index], arr[index], denominator);
			index++;
		}
	}

	public static void probability(int n0, int n, int[] arr, int s) {
		if (n <= 0) {
			arr[s - n0]++;
			return;
		}
		for (int i = 1; i <= 6; i++) {
			probability(n0, n - 1, arr, s + i);
		}
	}
}